home *** CD-ROM | disk | FTP | other *** search
- Path: fido.asd.sgi.com!austern
- From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
- Newsgroups: comp.std.c++
- Subject: Re: Are all Windows programs ill-formed?
- Date: 01 Feb 1996 09:07:11 PST
- Organization: Computer Science, University of Melbourne, Australia
- Approved: austern@isolde.mti.sgi.com
- Message-ID: <9602010236.26117@mulga.cs.mu.OZ.AU>
- References: <AE5J83na99@qsar.chem.msu.su>
- NNTP-Posting-Host: isolde.mti.sgi.com
- Summary: yes, almost all of them are ill-formed
- X-Original-Date: Thu, 1 Feb 1996 13:36:58 +1100
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBVAwUBMRDzUky4NqrwXLNJAQGgfQIAgn14/VwhL+H8aqX5l8o1hW1sXD4bxiZC
- lsDWDl6k1zLockoMBRvek0Te2X3j2uoWyWQLQxssPVgDelXUzhS4WA==
- =eYgs
- Originator: austern@isolde.mti.sgi.com
-
- "Eugene Radchenko" <eugene@qsar.chem.msu.su> writes:
-
- >I have just realized that something is grossly overlooked in C++ standard.
-
- I think the problem is due to Microsoft overlooking the C and C++
- standards, not vice versa.
-
- >It requires every program to have the main() function (which implementation
- >is not allowed to supply) with parameters (void) or (int argc, int*argv[]).
-
- The implementation is allowed to make the program work even if main() is
- not defined, so long as it issues a diagnostic.
-
- >However, Windows programs have another convention: prrogram must contain
- >the function
- > int WinMain(HINSTANCE curInst, HINSTANCE prevInst, LPSTR cmdline, int cmdShow)
-
- A compiler is allowed to accept the program
-
- int WinMain(HINSTANCE curInst, HINSTANCE prevInst, LPSTR cmdline,
- int cmdShow)
- {
- return 0;
- }
-
- so long as it issues at least one diagnostic, e.g.
- "warning: standard C++ requires a definition of main()".
-
- But if a compiler does not accept
-
- int main() { return 0; }
-
- as a complete program, then that compiler is not a conforming C or C++
- implementation.
-
- >Some of this is of course quirks or even outright ignored in Win32
- >(prevInst), but the full non-parsed command line could be useful sometimes,
- >and not all implementations provide the function retrieving it.
-
- In many operating systems, the command-line parsing is done by the
- shell, not the OS. Such operating systems cannot provide the non-parsed
- command line.
-
- >And anyway this is definitely not a main() from the specs.
- >Maybe the requirements on the main() should be relaxed somehow?
-
- Are you suggesting relaxing the requirements on implementations,
- or the requirements on programs?
-
- I presume you are referring to 3.6.1[basic.start.main]/1:
-
- | A program shall contain a global function called main, which is the
- | designated start of the program.
-
- You are correct to infer that this means that all Windows programs
- which do not define main() are ill-formed.
-
- However, that means only that a compiler is required to issue
- a diagnostic; it does not mean that the compiler must reject the
- program.
-
- Obviously a program that does not define main() is not going to be
- portable, so I don't think that requirement on programs should be
- relaxed.
-
- Windows compilers which wish to conform to the C and C++ standards
- should include code similar to
-
- HINSTANCE __curInst;
- HINSTANCE __prevInst;
- LPSTR __cmdline;
- int WinMain(HINSTANCE curInst, HINSTANCE prevInst, LPSTR cmdline,
- int cmdShow)
- {
- int argc;
- char **argv;
-
- __curInst = curInst;
- __prevInst = prevInst;
- __cmdLind = cmdLine;
- __parse_command_line(cmdline, &argc, &argv);
- return main(argc, argv);
- }
-
- in their libraries, so that they can accept programs which define main()
- but not WinMain().
-
- --
- Fergus Henderson WWW: http://www.cs.mu.oz.au/~fjh
- fjh@cs.mu.oz.au PGP: finger fjh@128.250.37.3
- ---
- [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
- Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
- is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
-